package com.heima.canal.entry;

import com.heima.canal.freemarker.ArticlePageHandler;
import com.heima.model.article.pojos.ApArticle;
import com.heima.search.api.ArticleEsFeign;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

/**
 * @author mgw
 * @create 2021/9/27 0:08
 */
@Component
@CanalTable(value = "ap_article")
public class ArticleEntry implements EntryHandler<ApArticle> {
    @Autowired
    private ArticlePageHandler articlePageHandler;
    @Autowired
    private ArticleEsFeign articleEsFeign;
    @SneakyThrows
    @Override
    public void insert(ApArticle apArticle) {
        System.out.println(apArticle);
        articlePageHandler.article(apArticle);

    }

    @Override
    public void update(ApArticle before, ApArticle after) {
        if (after.getIsDown()==0&&after.getIsDelete()==0){
        articleEsFeign.saveToEs(after);
        }
    }

    @Override
    public void delete(ApArticle apArticle) {
        System.out.println(apArticle);
    }

}
